/**
 * 
 */
package com.common.util;

/**
 * 分页工具类
 * @author zzx
 * @version 1.0
 */
public class Page {
	/** 默认15条/页 **/
	public static final int PAGESIZE = 20;
	
	/** 是否有上一页 */     
	private boolean hasPrePage;     

	/** 是否有下一页 */     
	private boolean hasNextPage;  
	
	/** 是否有上一页和下一页 */   
	private boolean hasPreAndNextPage;
	   
	/** 每页的数量 */     
	private int everyPageCount;     
	   
	/** 总页数 */     
	private int totalPage;     
	   
	/** 当前页*/     
	private int curPage;     
	   
	/** 总记录数*/     
	private int totalCount;
	/**
	 * 带参数的构造函数，(totalCount：总的纪录数 everyPageCount：每一页多少数据)
	 * @param totalCount 总的纪录数
	 * @param everyPageCount 每一页多少数据
	 */
	public Page(final int totalCount, final int everyPageCount,final int curPage){
		this.totalCount = totalCount;
		this.everyPageCount = everyPageCount;
		this.curPage = curPage == 0 ? 1 : curPage;
	}
	
	/**
	 * 是否有上一页 
	 * @return
	 */
	public boolean isHasPrePage() {
		return curPage == 1 ? false : true;
	}
	
	/**
	 * 是否有下一页
	 * @return
	 */
	public boolean isHasNextPage() {
		return curPage == getTotalPage() || getTotalPage() == 0 ? false : true;
	}
	/**
	 * 是否有上一页和下一页
	 * @return
	 */
	public boolean isHasPreAndNextPage() {
		return isHasPrePage() && isHasNextPage();
	} 
	
	public int getEveryPageCount() {
		return  everyPageCount == 0 ? PAGESIZE : everyPageCount;
	}

	public void seteveryPageCount(int everyPageCount) {
		this.everyPageCount = everyPageCount;
	}
	/**
	 * 总页数
	 * @return 
	 */
	public int getTotalPage() {
		if(totalCount % everyPageCount == 0)
			totalPage = totalCount/everyPageCount;
		else
			totalPage = totalCount/everyPageCount + 1;
		return totalPage;
	}

	public int getCurPage() {
		return curPage;
	}

	public void setCurPage(int curPage) {
		this.curPage = curPage;
	}

	public int getTotalCount() {
		return totalCount;
	}

	public void setTotalCount(int totalCount) {
		this.totalCount = totalCount;
	}
	
}
